<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- android.qdoc -->
  <title>Third-party Android Libraries | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Third-party Android Libraries</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#prerequisites">Prerequisites</a></li>
<li class="level1"><a href="#including-the-library-in-the-source">Including the Library in the Source</a></li>
<li class="level1"><a href="#adding-the-library-to-the-project-dependencies">Adding the Library to the Project Dependencies</a></li>
<li class="level1"><a href="#deployment">Deployment</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Third-party Android Libraries</h1>
<span class="subtitle"></span>
<!-- $$$android-3rdparty-libs.html-description -->
<div class="descr"> <a name="details"></a>
<p>This guide describes how to include a Java-based third-party library in your application package. There are many Java libraries which provide APIs that may be useful to your application. One example is the <code>Google Play Services</code> add-on provided in the Android SDK. We will use this library as an example in this guide, but the same approach may be taken to include other libraries, provided that they have been made to be included as library projects in an Android application.</p>
<a name="prerequisites"></a>
<h2 id="prerequisites">Prerequisites</h2>
<p>This guide assumes that the <a href="deployment-android.html#androiddeployqt">androiddeployqt</a> tool is used for constructing the deployment package. When using Qt Creator for building and deploying, androiddeployqt is used behind the scenes, so this also applies to development with Qt Creator. Explaining how to access the Java APIs after they have been included in the application is not in the scope of this guide.</p>
<a name="including-the-library-in-the-source"></a>
<h2 id="including-the-library-in-the-source">Including the Library in the Source</h2>
<p>The very first thing we need to do is to copy the actual library project into the source of our project. We want the contents of the library project to be copied without modifications into the packaging directory, so we need to place it into the <code>Android Package Source Directory</code>. This can be any directory which is pointed to by the <a href="../qmake/qmake-manual.html">qmake</a> variable <code>ANDROID_PACKAGE_SOURCE_DIR</code>.</p>
<p>If you are using Qt Creator, you can quickly set up the directory structure by clicking on the <b>Create AndroidManifest.xml</b> button in the <b>Deployment</b> settings of your project. This will create an <code>Android Package Source Directory</code> and place the <code>AndroidManifest.xml</code> file inside it. Copy the library project directory into this directory.</p>
<p>For example, once it has been installed via the <code>Android SDK Maintenance</code> application, the <code>Google Play Services</code> library project is located under the path <code>$ANDROID_SDK_ROOT/extras/google/google_play_services/libproject/google-play-services_lib</code>. If the <code>Android Package Source Directory</code> of our project is <code>$PROJECT_ROOT/android</code>, then we can copy the <code>google-play-services_lib</code> directory in there, creating <code>$PROJECT_ROOT/android/google-play-services_lib</code>.</p>
<a name="adding-the-library-to-the-project-dependencies"></a>
<h2 id="adding-the-library-to-the-project-dependencies">Adding the Library to the Project Dependencies</h2>
<p>Once the library code has been copied into the project, we need to tell the Android build system about it. This is done in the <code>project.properties</code> file. Create a file called <code>project.properties</code> inside the <code>Android Package Source Directory</code> and add a line to it which assigns the relative path of the library project to the property <code>android.library.reference.1</code>. If you want to include multiple library projects, increment the counter at the end of the property name for each.</p>
<p>In our example, we would create <code>$PROJECT_ROOT/android/project.properties</code> and add the following contents:</p>
<pre class="cpp plain">

  android.library.reference.1=google-play-services_lib/

</pre>
<a name="deployment"></a>
<h2 id="deployment">Deployment</h2>
<p>And that's it: Provided that the path referenced in the <code>project.properties</code> file is located under the <code>Android Package Source Directory</code>, the deployment tool will copy it into the packaging directory and perform the necessary steps to include it in your <code>APK</code> or <code>AAB</code>. You can now add Java code to your application which accesses the APIs provided by the library project.</p>
</div>
<!-- @@@android-3rdparty-libs.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
